package po;

import java.io.Serializable;
import java.util.HashSet;

public class CatalogPO implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private int id;
	private String name;
	private CatalogPO superCatalog;
	private HashSet<CatalogPO> subCatalog;
	private HashSet<Integer> bookIDList;
	
	public CatalogPO(int id, String name, CatalogPO superCatalog,
			HashSet<CatalogPO> subCatalog, HashSet<Integer> bookIDList) {
		super();
		this.id = id;
		this.name = name;
		this.superCatalog = superCatalog;
		this.subCatalog = subCatalog;
		this.bookIDList = bookIDList;
	}
	
	public CatalogPO() {
		this.id = 0;
		this.name = "";
		this.superCatalog = null;
		this.subCatalog = null;
		this.bookIDList = new HashSet<Integer>();
	}

	@Override
	public String toString() {
		return "CatalogPO [id=" + id + ", name=" + name + ", superCatalog="
				+ superCatalog.name + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((bookIDList == null) ? 0 : bookIDList.hashCode());
		result = prime * result + id;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result
				+ ((subCatalog == null) ? 0 : subCatalog.hashCode());
		result = prime * result
				+ ((superCatalog == null) ? 0 : superCatalog.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CatalogPO other = (CatalogPO) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	public int getId() {
		return id;
	}
	
	public String getName() {
		return name;
	}
	
	public CatalogPO getSuperCatalog() {
		return superCatalog;
	}
	
	public HashSet<CatalogPO> getSubCatalog() {
		return subCatalog;
	}
	
	public HashSet<Integer> getBookIDList() {
		return bookIDList;
	}

}
